﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
using CustomControls;
using PluginInterface;

namespace Buccaneer
{
    public partial class TheForm
    {
        public void Initialize()
        {
            #region self

            this.StartPosition = FormStartPosition.Manual;
            this.Location = new Point(200, 100);
            this.FormBorderStyle = FormBorderStyle.None;
            this.BackgroundImage = (Image)Options.GetResource("formBack");
            this.Size = this.BackgroundImage.Size;
            this.DoubleBuffered = true;

            #endregion

            #region addressbar

            this.abr_pathBox = new AddressBar();
            this.abr_pathBox.Location = new Point(132, 59);
            this.abr_pathBox.Size = new Size(570, 38);
            this.abr_pathBox.KeyUp += new KeyEventHandler(abr_pathBox_KeyUp);

            MainProgram.Plugins.RegisterAction("navigate", new ActionFunction(this.Navigate));

            this.Controls.Add(this.abr_pathBox);

            #endregion

            #region navigation

            this.pnl_navigation = new Panel();
            this.pnl_navigation.Size = new Size(139, 100);
            this.pnl_navigation.BackColor = Color.Transparent;

            this.bbn_back = BitmapButtonsInitializer.AddNavigateBack();
            this.bbn_back.Click += new EventHandler(bbn_back_Click);
            this.pnl_navigation.Controls.Add(this.bbn_back);
            this.bbn_up = BitmapButtonsInitializer.AddNavigateUp();
            this.bbn_up.Click += new EventHandler(bbn_up_Click);
            this.pnl_navigation.Controls.Add(this.bbn_up);
            this.bbn_down = BitmapButtonsInitializer.AddNavigateDown();
            this.bbn_down.Click += new EventHandler(bbn_down_Click);
            this.pnl_navigation.Controls.Add(this.bbn_down);
            this.bbn_forward = BitmapButtonsInitializer.AddNavigateForward();
            this.bbn_forward.Click += new EventHandler(bbn_forward_Click);
            this.pnl_navigation.Controls.Add(this.bbn_forward);

            this.Controls.Add(pnl_navigation);

            #endregion

            #region control

            this.pnl_control = new Panel();
            this.pnl_control.Size = new Size(102, 100);
            this.pnl_control.Location = new Point(697, 0);
            this.pnl_control.BackColor = Color.Transparent;


            this.bbn_go = BitmapButtonsInitializer.AddControlGo();
            this.bbn_go.Click += new EventHandler(bbn_go_Click);
            this.pnl_control.Controls.Add(this.bbn_go);

            this.bbn_close = BitmapButtonsInitializer.AddControlClose();
            this.bbn_close.Click += new EventHandler(bbn_close_Click);
            this.pnl_control.Controls.Add(this.bbn_close);

            this.Controls.Add(pnl_control);

            #endregion

            #region tabs

            this.pnl_plugin = new Panel();
            this.pnl_plugin.Size = new Size(786, 475);
            this.pnl_plugin.Location = new Point(7, 116);
            this.pnl_plugin.BackColor = Color.Transparent;
            this.pnl_plugin.Controls.Add(MainProgram.selectedPlugin.Instance.MainInterface);

            //this.Controls.Add(this.pnl_tabs);
            this.Controls.Add(this.pnl_plugin);

            #endregion
        }

        #region Private Attributes

        #region navigation panel

        Panel pnl_navigation;
        BitmapButton bbn_back, bbn_up, bbn_forward, bbn_down;

        #endregion
        #region control panel

        Panel pnl_control;
        BitmapButton bbn_go, bbn_close;

        #endregion

        AddressBar abr_pathBox;

        Panel pnl_tabs;
        
        #endregion

        #region Public Attributes

        //public TabHandler tabHandler;
        //public Addressbar abr_address;
        public Panel pnl_browsePlugin;
        public Panel pnl_plugin;
        public TextBox tbx_controller;

        #endregion

        #region Eventhandlers

        void bbn_forward_Click(object sender, EventArgs e)
        {
            MainProgram.Plugins.Act("navigateforward", new string[] { "navigate.forward button clicked" });
        }

        void bbn_down_Click(object sender, EventArgs e)
        {
            MainProgram.Plugins.Act("navigatedown", new string[] { "navigate.down button clicked" });
        }

        void bbn_up_Click(object sender, EventArgs e)
        {
            MainProgram.Plugins.Act("navigateup", new string[] { "navigate.up button clicked" });
        }

        void bbn_back_Click(object sender, EventArgs e)
        {
            MainProgram.Plugins.Act("navigateback", new string[] { "navigate.back button clicked" });
        }

        void bbn_close_Click(object sender, EventArgs e)
        {
            MainProgram.Plugins.Act("exit", new string[] { "exit button clicked" });
        }

        void bbn_go_Click(object sender, EventArgs e)
        {
            MainProgram.Plugins.Act("navigate", new string[] { this.abr_pathBox.Text });
        }

        void abr_pathBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                MainProgram.Plugins.Act("navigate", new string[] { this.abr_pathBox.Text });
            }
        }

        #endregion

        #region ActionFunctions

        public void Navigate(string[] args)
        {
            this.abr_pathBox.Text = args[0];
        }

        #endregion
    }
}
